//
//  YTDeviceContentView.m
//  YUNT
//
//  Created by 梁炜东 on 2017/11/27.
//  Copyright © 2017年 梁炜东. All rights reserved.
//

#import "YTDeviceContentView.h"
#import "CCCycleScrollView.h"
#import "YTListDeviceCell.h"
#import "XYButton.h"

@interface YTDeviceContentView()<CCCycleScrollViewClickActionDeleage, UITableViewDelegate, UITableViewDataSource>
@property(nonatomic, strong)UIImageView *iconImage;
@property(nonatomic, strong)UILabel *connectLabel;
@property(nonatomic, strong)UIButton *paramButton;
@property(nonatomic, strong)UITableView *listTableView;
@property(nonatomic, strong)CCCycleScrollView *cycleScrollView;//轮播图
@property(nonatomic, strong)UIButton *connectBleBtn;
@property(nonatomic, strong)UIButton *infoButton;
//@property(nonatomic, strong)XYButton *deviceButton;
@end

@implementation YTDeviceContentView

-(instancetype)init
{
    self = [super init];
    if (self)
    {
        self.frame = [UIScreen mainScreen].bounds;
        [self p_addSubView];
        [self p_makeConstraints];
    }
    return self;
}
#pragma mark CCCycleScrollViewClickActionDeleage
-(void)cyclePageClickAction:(NSInteger)clickIndex
{
    
}
-(void)connectBleBtnAction:(UIButton *)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(delegateDeviceContentViewbType:)])
    {
        [self.delegate delegateDeviceContentViewbType:YTDeviceContentViewButtonConnect];
    }
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 0;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    YTListDeviceCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YTListDeviceCell" forIndexPath:indexPath];
    return cell;
}
#pragma mark private sub view and frame
-(void)p_addSubView
{
    [self addSubview:self.iconImage];
//    [self addSubview:self.listTableView];
    [self addSubview:self.connectLabel];
    [self addSubview:self.paramButton];
    [self addSubview:self.cycleScrollView];
    [self addSubview:self.connectBleBtn];
    [self addSubview:self.infoButton];
//    [self addSubview:self.deviceButton];
}
-(void)p_makeConstraints
{
    [_cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.width.mas_equalTo(250*0.9);
        make.height.mas_equalTo(378*0.9);
    }];
//    [_listTableView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.equalTo(self);
//        make.leading.equalTo(self).offset(50);
//        make.trailing.equalTo(self).offset(-50);
//        make.height.mas_equalTo(39);
//        make.top.equalTo(_cycleScrollView.mas_top).offset(-15-50);
//    }];
    [_connectLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_cycleScrollView.mas_top).offset(-22);
        make.leading.trailing.equalTo(self);
        make.height.mas_equalTo(30);
    }];
    [_iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(46);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(30);
        make.centerX.equalTo(self);
    }];
    [_paramButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_iconImage);
        make.trailing.equalTo(self).offset(-22);
        make.width.mas_equalTo(16);
        make.height.mas_equalTo(15);
    }];
    [_connectBleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.leading.equalTo(self).offset(50);
        make.trailing.equalTo(self).offset(-50);
        make.top.equalTo(_cycleScrollView.mas_bottom).offset(12);
    }];
    [_infoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_connectBleBtn.mas_bottom).offset(6);
        make.leading.trailing.equalTo(self);
        make.height.mas_equalTo(20);
    }];
//    [_deviceButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.bottom.leading.trailing.equalTo(self);
//        make.height.mas_equalTo(78);
//    }];
}
-(UIImageView *)iconImage
{
    if (!_iconImage)
    {
        _iconImage = [[UIImageView alloc] init];
        _iconImage.image = IMAGE(@"03_01");
        _iconImage.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _iconImage;
}
-(UILabel *)connectLabel
{
    if (!_connectLabel)
    {
        _connectLabel = [[UILabel alloc] init];
        _connectLabel.text = Language(@"连接你的ZYX设备");
        _connectLabel.textAlignment = NSTextAlignmentCenter;
        _connectLabel.textColor = YTColor(160, 160, 160);
        _connectLabel.font = [UIFont systemFontOfSize:16];
    }
    return _connectLabel;
}
-(UIButton *)paramButton
{
    if (!_paramButton)
    {
        _paramButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _paramButton.backgroundColor = [UIColor clearColor];
        [_paramButton setImage:IMAGE(@"03_02") forState:UIControlStateNormal];
    }
    return _paramButton;
}
-(UITableView *)listTableView
{
    if (!_listTableView)
    {
        _listTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
        _listTableView.delegate = self;
        _listTableView.dataSource = self;
        [_listTableView registerClass:[YTListDeviceCell class] forCellReuseIdentifier:@"YTListDeviceCell"];
        _listTableView.backgroundColor = [UIColor clearColor];
    }
    return _listTableView;
}
-(CCCycleScrollView *)cycleScrollView
{
    if (!_cycleScrollView)
    {
        NSArray *images = @[IMAGE(@"03_03"), IMAGE(@"03_03")];
        _cycleScrollView = [[CCCycleScrollView alloc]initWithImages:images withFrame:CGRectMake(ScreenWidth/2-250*0.9/2, ScreenHeight/2-378*0.9/2, 250*0.9, 378*0.9)];
//        _cycleScrollView.pageDescrips = @[@"test",@"test"];
        _cycleScrollView.delegate = self;
        _cycleScrollView.backgroundColor = [UIColor clearColor];
        [self addSubview:_cycleScrollView];
    }
    return _cycleScrollView;
}
-(UIButton *)connectBleBtn
{
    if (!_connectBleBtn)
    {
        _connectBleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _connectBleBtn.backgroundColor = YTColor(151, 75, 160);
        _connectBleBtn.titleLabel.font = [UIFont systemFontOfSize:18];
        [_connectBleBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _connectBleBtn.layer.cornerRadius = 10;
        _connectBleBtn.layer.masksToBounds = YES;
        _connectBleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        _connectBleBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        [_connectBleBtn setTitle:Language(@"连接设备") forState:UIControlStateNormal];
        [_connectBleBtn addTarget:self action:@selector(connectBleBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _connectBleBtn;
}
-(UIButton *)infoButton
{
    if (!_infoButton)
    {
        _infoButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _infoButton.backgroundColor = [UIColor clearColor];
        _infoButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [_infoButton setTitleColor:YTColor(160, 160, 160) forState:UIControlStateNormal];
        _infoButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        _infoButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        [_infoButton setTitle:Language(@"了解更多") forState:UIControlStateNormal];
    }
    return _infoButton;
}
//-(XYButton *)deviceButton
//{
//    if (!_deviceButton)
//    {
//        _deviceButton = [XYButton buttonWithType:UIButtonTypeCustom];
//        _deviceButton.backgroundColor = [UIColor clearColor];
//        _deviceButton.titleLabel.font = [UIFont systemFontOfSize:15];
//        _deviceButton.titlePosition = XYButtonTitlePositionBottom;
//        [_deviceButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        _deviceButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
//        _deviceButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
//        [_deviceButton setImage:IMAGE(@"03_05") forState:UIControlStateNormal];
//        [_deviceButton setTitle:Language(@"设备") forState:UIControlStateNormal];
//    }
//    return _deviceButton;
//}
@end
